package com.example.noval.utils.ext

import android.content.Context
import android.view.View
import androidx.appcompat.app.AppCompatActivity

/**
 * @Description
 * @Author zzl
 * @Date 2024/4/1
 */
private tailrec fun getCompatActivity(context: Context?): AppCompatActivity? {
    return when (context) {
        is AppCompatActivity -> context
        is androidx.appcompat.view.ContextThemeWrapper -> getCompatActivity(context.baseContext)
        is android.view.ContextThemeWrapper -> getCompatActivity(context.baseContext)
        else -> null
    }
}

val View.activity: AppCompatActivity?
    get() = getCompatActivity(context)